package com.example.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 */
@Configuration //将当前类托管到Spring容器中

public class AppConfig implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("api",c -> true);
    }

    /**配置拦截规则
     *  /**表示拦截所有的接口，包含了对静态页面的拦截
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/api/user/login3")
                .excludePathPatterns("/api/user/login4")
                .excludePathPatterns("/api/user/reg")
                .excludePathPatterns("/api/user/index")
                .excludePathPatterns("/api/user/getcookie")
                .excludePathPatterns("/api/user/getalist")
                .excludePathPatterns("/api/article/del")
                .excludePathPatterns("/api/article/getdetail")
                .excludePathPatterns("/api/article/update")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/register.html")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/reg_error.html")
                .excludePathPatterns("/myblog_list.html")
                .excludePathPatterns("/blog_edit.html")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.jpg")
                .excludePathPatterns("/**/*.png");
    }
}
